﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using PSE.AuditLogging.Client.Configuration;
using System.Threading;
using PSE.AuditLogging.ContingencyService.Management.ServiceContracts;
using PSE.AuditLogging.Common.Service;
using PSE.AuditLogging.ContingencyService.ServiceImplementation;
using PSE.Framework.ErrorLogging;

namespace PSE.AuditLogging.ContingencyService
{
    public partial class Service1 : ServiceBase
    {
        private ServiceHoster _serviceManagerHost;

        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            ServiceExecutor executor = ServiceExecutor.GetInstance();
            ServiceExecutor.GetInstance().Start();

            if (!executor.IsRunning)
                this.Stop();
            else
            {
                _serviceManagerHost = new ServiceHoster(Constants.SERVICE_MANAGER_NETPIPE_ADDRESS, typeof(IServiceManager), typeof(ServiceManager));
                _serviceManagerHost.Open();
            }
        }

        protected override void OnStop()
        {
            ServiceExecutor.GetInstance().Stop();
            _serviceManagerHost.Close();
        }
    }
}
